

// 获取swiper
var sw = document.querySelector('.swiper-wrapper')

//发送请求获取轮播图图片
var xhr = new XMLHttpRequest()
xhr.open('get','http://47.116.75.38:8101/front/carousel')
xhr.send(null)
xhr.onload = function () {
  var res = JSON.parse(xhr.response)
  res.data.records.forEach(function (item) {
    var div = document.createElement('div')
    div.className = 'swiper-slide'
    var img = document.createElement('img')
    img.src = item.image
    div.appendChild(img)
    sw.appendChild(div)


  })
  //获取所有轮播图div
  var lunbos = document.querySelectorAll('.swiper-slide')
  for(let i = 0; i < lunbos.length; i++){
    lunbos[i].onclick = function () {
      if( i === lunbos.length-1){
        window.location.href = 'shiping.html'
      }else {
        window.location.href = 'login.html'
      }


    }
  }

  // 初始化swiper
  var swiper = new Swiper(".swiper", {
    loop: true, // 循环模式选项
    // effect:'cube',
    autoplay:true,

    pagination: {
      el: ".swiper-pagination",
    },
  });
}



//获取语言服务的所有父级
var kil = document.querySelectorAll('.kf-item-list')
//发送请求获取语言服务康复群体
var xhr1 = new XMLHttpRequest()
xhr1.open('get','http://47.116.75.38:8101/front/getService')
xhr1.send(null)
xhr1.onload = function () {
  var res = JSON.parse(xhr1.response)
  res.data.forEach(function (item,index) {
    try {
      var h3 = document.createElement('h3')
      h3.innerText = item.dictName
      kil[index].appendChild(h3)
    }catch (e) {
      console.log(e)
    }
  })
}


//获取所有课程
var keC = document.querySelector('.keC-list')
var kIcon = ['icon-shu','icon-shu','icon-shu','icon-shu']
var xhr2 = new XMLHttpRequest()
xhr2.open('get','http://47.116.75.38:8101/front/getCourseCls')
xhr2.send(null)
xhr2.onload = function () {
  var res = JSON.parse(xhr2.response)
  res.data.forEach(function (item,index) {
    var a = document.createElement('a')
    a.className = 'keC-list-li'
    a.href = 'star.html'
    // div.style.background = 'url('+kI[index]+')  center top;'
    var i = document.createElement('i')
    i.className = 'iconfont '+kIcon[index]
    var h3 = document.createElement('h3')
    h3.innerText = item.dictLabel
    a.appendChild(i)
    a.appendChild(h3)
    keC.appendChild(a)
    keC.style.setProperty('--c',res.data.length)
  })

}

//获取所有新闻
var xwlis = document.querySelector('.xw-list')
var xhr3 = new XMLHttpRequest()
xhr3.open('get','http://47.116.75.38:8101/front/pageList')
xhr3.send(null)
xhr3.onload = function () {
  res = JSON.parse(xhr3.response)
  if (res.data.records.length === 0){
    xwlis.innerText = '暂无数据哦~'
  }else {
    res.data.records.forEach(function (item) {
      var a = document.createElement('a')
      var p = document.createElement('p')
      p.innerText = item.title
      var span = document.createElement('span')
      span.innerText = item.createTime
      a.appendChild(p)
      a.appendChild(span)
      xwlis.appendChild(a)
    })
  }
}

//点击新闻获取新闻信息
var yanYu = document.querySelector('.yanYu')
var xinWen = document.querySelector('.xinWen')
xinWen.onclick = function () {
  xwlis.innerText = ' '
  yanYu.classList.remove('c')
  xinWen.classList.add('c')
  var xhr4 = new XMLHttpRequest()
  xhr4.open('get','http://47.116.75.38:8101/front/pageList?resourceClass=xwzx')
  xhr4.send(null)
  xhr4.onload = function () {
    res = JSON.parse(xhr4.response)
    if (res.data.records.length === 0){
      xwlis.innerText = '暂无数据哦~'
    }else {
      res.data.records.forEach(function (item) {
        var a = document.createElement('a')
        var p = document.createElement('p')
        p.innerText = item.title
        var span = document.createElement('span')
        span.innerText = item.createTime
        a.appendChild(p)
        a.appendChild(span)
        xwlis.appendChild(a)
      })
    }
  }
}

//点击言语科普获取信息
yanYu.onclick = function () {
  xwlis.innerText = ' '
  xinWen.classList.remove('c')
  yanYu.classList.add('c')
  var xhr5 = new XMLHttpRequest()
  xhr5.open('get','http://47.116.75.38:8101/front/pageList?resourceClass=zykp')
  xhr5.send(null)
  xhr5.onload = function () {
    res = JSON.parse(xhr5.response)
    if (res.data.records.length === 0){
      xwlis.innerText = '没有数据哦~'
    }else {
      res.data.records.forEach(function (item) {
        var a = document.createElement('a')
        var p = document.createElement('p')
        p.innerText = item.title
        var span = document.createElement('span')
        span.innerText = item.createTime
        a.appendChild(p)
        a.appendChild(span)
        xwlis.appendChild(a)
      })
    }
  }
}


